#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File        :   101. 对称二叉树.py    
@Contact     :   lhouctcs@163.com
@License     :   MIT
@Time        :   2023/2/15 22:16
@Author      :   lhou 
@Version     :   0.1.0
@Description :
"""
from typing import Optional


# import lib
# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    def isSymmetric(self, root: Optional[TreeNode]) -> bool:
        def iss(left, right):
            if not left and not right:
                return True
            if left and not right:
                return False
            if right and not left:
                return False
            if right.val != left.val:
                return False
            if right.val == left.val:
                return iss(left.left, right.right) and iss(left.right, right.left)

        if not root:
            return True
        return iss(root.left, root.right)
